package com.gaobug.platform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaobug.base.annotation.BindUser;
import com.gaobug.base.response.ResponseWrapped;
import com.gaobug.platform.domain.CommentInfo;
import com.gaobug.platform.dto.CommentDTO;
import com.gaobug.platform.dto.VoteDTO;
import com.gaobug.platform.service.CommentInfoService;
import com.gaobug.verify.Verify;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 博客首页相关接口
 */
@RestController
@RequestMapping("/blog/comment")
public class BlogCommentController {

    @Resource
    private CommentInfoService commentService;

    @BindUser
    @PostMapping
    public ResponseWrapped<Object> commentBlog(@RequestBody CommentDTO commentDTO) {
        commentService.commentBlog(commentDTO);
        return ResponseWrapped.successSave();
    }

    @GetMapping("page")
    public ResponseWrapped<Object> commentPage(@Verify(required = true, errorMsg = "文章标识为空") String articleId, Page<CommentInfo> page) {
        return ResponseWrapped.success(commentService.commentPage(articleId, page));
    }

    @BindUser
    @GetMapping("expand/page")
    public ResponseWrapped<Object> commentExpandPage(@Verify(required = true, errorMsg = "评论标识为空") String commentId, Page<CommentInfo> page) {
        return ResponseWrapped.success(commentService.commentExpandPage(commentId, page));
    }

    @BindUser
    @PostMapping("del/{id}")
    public ResponseWrapped<Object> commentDel(@PathVariable Long id) {
        commentService.commentDel(id);
        return ResponseWrapped.successDelete();
    }

    @BindUser
    @PostMapping("like")
    public ResponseWrapped<Object> commentLike(@RequestBody VoteDTO voteDTO) {
        commentService.commentLike(voteDTO);
        return ResponseWrapped.success();
    }
}
